package com.lanp.gencode.fileInfo;

import com.lanp.gencode.utils.SigoStrUtils;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.List;

@Data
public class FileInfo {
    private String authorInfo;
    private List<String> classAnnotations;//类注解
    private String className;
    private String javaType;
    private String packageName;
    private String extentsName;
    private String implClassName;
    private List<String> importList;
    private FieldInfo myMapperField;//当前mapper的变量信息
    private FieldInfo myServiceField;//当前service的变量信息
    private List<FieldInfo> fieldInfoList;
    private List<MethodInfo> methodInfoList;

    public boolean isOverride(){
        return StringUtils.isNotBlank(implClassName) ? true : false;
    }

    @Data
    public static class FieldInfo {
        private String accessType = "private";//访问修饰符
        private String fieldType;
        private String fieldName;
        private String remark;
        private Boolean isAutowired = false;
    }

    public static FieldInfo autoField(String fieldType) {
        FieldInfo res = new FieldInfo();
        res.setFieldType(fieldType);
        res.setFieldName(SigoStrUtils.getVarName(fieldType));
        res.setIsAutowired(true);
        return res;
    }

    public static FieldInfo newField(String fieldType) {
        FieldInfo res = new FieldInfo();
        res.setFieldType(fieldType);
        res.setFieldName(SigoStrUtils.getVarName(fieldType));
        return res;
    }

    @Data
    public static class MethodInfo {
        private String accessType = "public";//访问修饰符
        private String refundType;
        private List<String> inParams;//入参
        private String methodName;
        private String methodRemark;
        private String methodContext;
        private Boolean isRouter;//是否需要路由
    }
}